import random
import pgzrun

WIDTH = 720
HEIGHT = 720

l = list(range(1,10))
s = []


random.shuffle(l)
    
s.append(l[:])

def Roll(t):
    global l,s
    for i in range(t):
        l.append(l[0])
        l.remove(l[0])
    
    s.append(l[:])

def do():
    for i in range(8):
        if i % 3 == 2:
            Roll(1)
        else:
            Roll(3)
        
ss = s[:]
do()

def f():
    global s
    for i in range(random.randint(40,70)):
        x,y = random.randint(0,8),random.randint(0,8)
        while s[x][y] == 0:
            x,y = random.randint(0,8),random.randint(0,8)            
            
        s[x][y] = 0
        
f()

zero = Actor('black.png')
uno = Actor('1.png')
due = Actor('2.png')
tre = Actor('3.png')
quattro = Actor('4.png')
cinque = Actor('5.png')
sei = Actor('6.png')
sette = Actor('7.png')
otto = Actor('8.png')
nove = Actor('9.png')
nums = [zero,uno,due,tre,quattro,cinque,sei,sette,otto,nove]
dl = []
fsize = 80

for i in range(0,len(s)):
    for j in range(0,len(s[i])):
        dl.append((nums[s[i][j]],((i + 1)* fsize - fsize / 2,(j + 1) * fsize - fsize / 2)) )
        
def draw():
    for i in dl:
        i[0].pos = i[1]
        i[0].draw()
        
pgzrun.go()
